import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * Created with IDEA
 * Author : wangfei
 * Date :  2016/7/21
 * Time : 17:35
 * Describe :
 */
public class JmsSender {
	public static  void main(String[] args){
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");

		try {
			Connection connection = connectionFactory.createConnection();
			connection.start();

			Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
			Destination destination = session.createQueue("Test.foo");

			MessageProducer producer = session.createProducer(destination);
			producer.setDeliveryMode(DeliveryMode.PERSISTENT);
			for(int i=0; i<100; i++) {
				int id = i+1;
				ObjectMessage message = session.createObjectMessage();
				message.setObject(new User(id, "张三"+id, "123456"));
				producer.send(message);
			}
			session.commit();
			session.close();
			connection.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
